﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Utility.BehaviourTree
{
	public class SelectorNode : CompositeNode
	{
		int currIndex = 0;

		protected override Status OnUpdate ()
		{
			BTNode curr;
			while (currIndex < childNodes.Count)
			{
				curr = childNodes[currIndex];
				switch (curr.Update ())
				{
					case Status.Success:
						return Status.Success;
					case Status.Failure:
						currIndex++;
						break;
					case Status.Running:
						return Status.Running;
				}
			}

			return Status.Failure;
		}

		protected override void OnReset ()
		{
			base.OnReset ();
			currIndex = 0;
		}
	}
}